import random
import time

import requests

from Common.basepage import BasePage
from PageObjects.Main_page import MainPage
from PageObjects.Player_page import PlayerPage


def player_stress():
    player_page = PlayerPage("d_one")
    operations = {
        "next": (player_page.click_next, 5),
        "play": (player_page.click_play, 2),
        "schedule": (player_page.click_random_schedule, 5),
        "rate": (player_page.click_random_rate, 5)
    }

    operate = random.choices(list(operations.keys()), weights=(3, 2, 3, 2), k=1)[0]
    operation, delay = operations[operate]
    operation()
    time.sleep(delay)


def DP_stress():
    BasePage("d_one").start_middleware_app()
    time.sleep(2)
    MainPage("d_one").click_SynPlay()
    time.sleep(1)
    MainPage("d_one").click_share()
    time.sleep(1)
    MainPage("d_one").click_slave_invite()
    time.sleep(2)
    MainPage("d_one").click_point(0.4, 0.5, img_desc="点击空白处返回")
    time.sleep(2)
    while True:
        try:
            player_stress()
        except:
            requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/多屏1.0自动操作脚本可能出现问题")


def player_stress_next():
    player_page = PlayerPage("d_one")

    player_page.click_finish_schedule()
    time.sleep(300)


if __name__ == '__main__':
    while True:
        try:
            DP_stress()
        except:
            requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/多屏1.0自动操作脚本可能出现问题")
